package com.xiaouyudeguang.common.encrypt;

import com.xiaouyudeguang.common.constants.Headers;
import com.xiaouyudeguang.common.respose.ResultDto;
import com.xiaouyudeguang.common.service.AbstractService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class EncryptResource {

    @Autowired(required = false)
    private List<AbstractService<?, ?>> serviceList;

    @Transactional
    @RequestMapping(value = "/encrypt", method = RequestMethod.PUT)
    public ResultDto<Boolean> encrypt(@RequestHeader(Headers.TENANT_ID) String tenantId,
                                      @RequestHeader(Headers.APP_ID) String appId) throws Exception {
        for (AbstractService<?, ?> baseService : serviceList) {
            baseService.encrypt(tenantId, appId);
        }
        return ResultDto.ok(true);
    }
}
